// mockData.js
let views = [
  {
    id: 1,
    name: '示例网络拓扑',
    data: {
      nodes: [
        {
          id: 1,
          label: "用户终端",
          group: 'user',
          type: 'user',
          color: '#409EFF',
          size: 40,
          font: { size: 14 },
          x: 100,
          y: 100,
          shape: 'circularImage',
          image: 'https://visjs.github.io/vis-network/examples/network/img/indonesia/1.png'
        },
        {
          id: 2,
          label: "Web服务器",
          group: 'server',
          type: 'server',
          color: '#67C23A',
          size: 40,
          font: { size: 14 },
          x: 300,
          y: 100,
          shape: 'circularImage',
          image: 'https://visjs.github.io/vis-network/examples/network/img/indonesia/1.png'
        },
        {
          id: 3,
          label: "防火墙",
          group: 'firewall',
          type: 'firewall',
          color: '#E6A23C',
          size: 40,
          font: { size: 14 },
          x: 200,
          y: 200,
          shape: 'circularImage',
          image: 'https://visjs.github.io/vis-network/examples/network/img/indonesia/1.png'
        }
      ],
      edges: [
        {
          id: 1,
          from: 1,
          to: 3,
          label: '访问',
          arrows: 'to',
          color: '#409EFF',
          width: 2
        },
        {
          id: 2,
          from: 3,
          to: 2,
          label: '转发',
          arrows: 'to',
          color: '#67C23A',
          width: 2
        }
      ]
    },
    options: {
      layout: { hierarchical: { enabled: false, direction: 'UD' } },
      physics: { enabled: true },
      edges: {
        smooth: { enabled: true },
        dashes: false,
        arrows: {
          to: { enabled: true }
        }
      },
      nodes: {
        size: 20,
        font: { size: 14 }
      }
    }
  }
];

let nextId = 4;
let nextEdgeId = 3;

export const mockDataStore = {
  // 获取所有视图
  getAllViews() {
    return [...views];
  },

  // 根据ID获取视图
  getViewById(id) {
    return views.find(view => view.id === id);
  },

  // 创建新视图
  createView(viewData) {
    const newView = {
      id: nextId++,
      ...viewData
    };
    views.push(newView);
    return newView;
  },

  // 更新视图
  updateView(id, viewData) {
    const index = views.findIndex(view => view.id === id);
    if (index !== -1) {
      views[index] = { ...views[index], ...viewData };
      return views[index];
    }
    return null;
  },

  // 删除视图
  deleteView(id) {
    const index = views.findIndex(view => view.id === id);
    if (index !== -1) {
      views.splice(index, 1);
      return true;
    }
    return false;
  },

  // 生成新的节点ID
  generateNodeId() {
    return nextId++;
  },

  // 生成新的边ID
  generateEdgeId() {
    return nextEdgeId++;
  }
};

// 节点模板定义 - 使用简单的颜色和文字图标
export const nodeTemplates = [
  {
    type: 'user',
    label: '用户终端',
    group: 'user',
    color: '#409EFF',
    size: 40,
    image: 'https://visjs.github.io/vis-network/examples/network/img/indonesia/1.png'
  },
  {
    type: 'server',
    label: '服务器',
    group: 'server',
    color: '#67C23A',
    size: 40,
    image: 'https://visjs.github.io/vis-network/examples/network/img/indonesia/1.png'
  },
  {
    type: 'firewall',
    label: '防火墙',
    group: 'firewall',
    color: '#E6A23C',
    size: 40,
    image: 'https://visjs.github.io/vis-network/examples/network/img/indonesia/1.png'
  },
  {
    type: 'router',
    label: '路由器',
    group: 'router',
    color: '#F56C6C',
    size: 40,
    image: 'https://visjs.github.io/vis-network/examples/network/img/indonesia/1.png'
  },
  {
    type: 'switch',
    label: '交换机',
    group: 'switch',
    color: '#909399',
    size: 40,
    image: 'https://visjs.github.io/vis-network/examples/network/img/indonesia/1.png'
  },
  {
    type: 'database',
    label: '数据库',
    group: 'database',
    color: '#9B59B6',
    size: 40,
    image: 'https://visjs.github.io/vis-network/examples/network/img/indonesia/1.png'
  }
];

// 如果无法使用在线图片，可以使用base64图标或字体图标
export const nodeIcons = {
  user: '👤',
  server: '🖥️',
  firewall: '🛡️',
  router: '📡',
  switch: '🔀',
  database: '💾'
};

// 备选方案：使用简单的base64图标
export const base64Icons = {
  user: '',
  server: '',
  firewall: ''
};